<%@ page language="java"
	import="java.util.*,edu.cnu.tpts.bean.*,edu.cnu.tpts.dao.*,edu.cnu.tpts.dao.impl.*"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/authorize.jsp"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'doupdateMessage.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		<%
			int id = Integer.parseInt(request.getParameter("id"));
			String password = request.getParameter("password");
			String repassword = request.getParameter("repassword");
			String loginname = request.getParameter("loginname");
			if (password.equals(repassword)) {
				Student stu = new Student();
				stu.setId(id);
				stu.setPassword(password);
				stu.setLoginName(loginname);
				StudentDao stuDao = new StudentDaoImpl();
				stuDao.updateStudent(stu);
				String type = (String) session.getAttribute("type");
				if (type.equals("student")) //如果是学生更新
					request.getRequestDispatcher("/student/showMessage.jsp")
							.forward(request, response);
				else
					//如果是管理员更新
					request.getRequestDispatcher("/admin/admin_stu.jsp").forward(request,
							response);
			} else {
				request.setAttribute("error", "密码和确认密码不一致");
				request.getRequestDispatcher("/student/updateMessage.jsp")
						.forward(request, response);
			}
		%>
	</body>
</html>
